package com.example.kingdee.exception;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.kingdee.kingdeeBridge.dto.BillWriteInDto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.log4j.Logger;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 *  本系统的手动捕获错误
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProcedureException extends RuntimeException{

    private Logger logger = Logger.getLogger(RuntimeException.class);

    private Integer code;
    private String msg;

    private String message;
    private Object[] data;

    public ProcedureException(ResponseEnum responseEnum, Object... data){
        this.code = Integer.valueOf(responseEnum.getCode());
        this.msg = responseEnum.getMessage();
        this.message = responseEnum.getMessage();
        this.data = data;
    }

    public ProcedureException(String msg, Object... data){
        String date = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
        String err = "%s，日志id：%s";
        this.code = 500;
        this.msg = StringUtils.format(err, msg, date);
        this.message = StringUtils.format(err, msg, date);
        this.data = data;
        if (data.length > 1){
            //将报错信息写入数据库

        }
    }

}
